package uniandes.dermatologia;

import java.util.Calendar;

import uniandes.dermatologia.models.PhysicalExamination.Border;
import uniandes.dermatologia.singleton.DermatologiaUniandesApp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RadioGroup;
import android.support.v4.app.NavUtils;

// public class BorderActivity extends Activity {

public class BorderActivity extends Activity {

	private RadioGroup groupActivity;
	private DatePicker startDate;

	@Override
	// public View onCreateView( LayoutInflater inflater, ViewGroup container,
	// Bundle savedInstanceState )
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_border);

		getActionBar().setDisplayHomeAsUpEnabled(false);

		groupActivity = (RadioGroup) findViewById(R.id.radioGroupBorder);
		startDate = (DatePicker) findViewById(R.id.datePickerStart);

		Button btnBack = (Button) findViewById(R.id.btnBackBorder);
		Button btnNext = (Button) findViewById(R.id.btnNextBorder);

		Typeface font = Typeface.createFromAsset(getAssets(),
				"fonts/Roboto-Light.ttf");

		btnBack.setTypeface(font);
		btnNext.setTypeface(font);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.border, menu);
		return false;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void onClickNext(View v) {

		Calendar fecha = Calendar.getInstance();
		fecha.set(startDate.getYear(), startDate.getMonth(),
				startDate.getDayOfMonth());
		
		((DermatologiaUniandesApp) getApplication()).getCurrentConsultation().setStartDate(fecha.getTime());

		if (groupActivity.getCheckedRadioButtonId() == R.id.radioPoorlyDemarcatedBorder) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setBorder(Border.poorly_demarcated);
		} else if (groupActivity.getCheckedRadioButtonId() == R.id.radioWellDemarcatedBorder) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setBorder(Border.well_demarcated);
		}

		Intent intent = new Intent(this, SymptomsActivity.class);
		startActivity(intent);
	}

	public void onClickBack(View v) {
		finish();
	}
}
